package bTree.LeetCode;

public class 最大连续1的个数3 {
    public int longestOnes(int[] nums, int k) {
        int length = nums.length;
        int left=0,right=0;
        int res=0;
        while (right<length){
            if (nums[right]==0){
                k--;
            }
            while (k<0){
                if (nums[left]==0){
                    k++;
                }
                left++;
            }
            right++;
            res=Math.max(res, right-left);
        }
        return res;
    }
}